import React, { Component } from 'react'

export default class Test2 extends Component {
	state = {carName:'奔驰'}
	render() {
		console.log('render执行了')
		return (
			<div>
				<h2>车名为：{this.state.carName}</h2>
				<button onClick={this.changeCar}>破产了，换车</button>
			</div>
		)
	}

	changeCar = ()=>{
		//对象式的setState --- 适用于：不依赖于原状态
		// this.setState({carName:'自行车'})

		//函数式的setState ---- 适用于：依赖于原状态
		this.setState( (state) => ({carName:'二手'+state.carName}))
	}
}
